package com.zhengke.controller.bbfx;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zhengke.common.object.Result;
import com.zhengke.common.util.FileExport;
import com.zhengke.pojo.GoodsSortAnaly;
import com.zhengke.service.bbfx.SortSalesService;
/**
 * *******************************
 * 	项目名称：tvmallws
 * 	文件名称：SortSalesController
 * 	类说明：  商品分类销售排行统计controller
 * @author 周梦坤
 * @version 1.0
 * *******************************
 */
@Controller
@RequestMapping("analysis")
public class SortSalesController {
	@Autowired
	SortSalesService service;
	
	@RequestMapping("queryClassification.do")
	public String querySorSales() {
		return "bbfx/spfl";
	}
	
	/**
	 * 	查询商品分类销售排行统计数据
     * @return
     */
    @ResponseBody
    @RequestMapping("querySortSaleRank.do")
    private Result querySortSaleRank(String channelName, String sTime, String eTime,int page, int limit){
        Result rs = null;
        try {
            rs = service.querySortSaleRank(channelName, sTime, eTime, page, limit);
            return rs;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new Result();
    }
    @SuppressWarnings("unchecked")
    @RequestMapping("export.do")
    public void export(HttpServletResponse response, String channelName, String sTime, String eTime) {
    	Result rs = null;
    	try {
            rs = service.querySortSaleRank(channelName, sTime, eTime, 0, 0);
            String[] topName = {"日期", "服务点名称","商品分类名称","销量"};
            List<Object[]> list = new ArrayList<Object[]>();
            for(GoodsSortAnaly bbfx :(List<GoodsSortAnaly>)rs.getData()) {
				 Object [] obj =new Object[topName.length];
				 obj[0]=bbfx.getDay();
				 obj[1]=bbfx.getAreaName();
				 obj[2]=bbfx.getGcName();
				 obj[3]=bbfx.getNum();
				 list.add(obj);
			 }			 
			FileExport.exportExcel(topName, list, "商品分类销量信息", response);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
